<template>
  <div :key="key">
    <center>
      <h3>南京市养老机构综合运营补贴申请表</h3>
    </center>
    <!-- 基本信息 -->
    <table align="center" border="1" cellpadding="5" cellspacing="0" width="100%" class="table1">
      <caption>（所属时间： 年第 季度）</caption>
      <caption>基本信息</caption>
      <tr>
        <td>机构名称</td>
        <td>{{ data.organizationName }}</td>
        <td>法定代表人</td>
        <td>{{ data.deputyUserName }}</td>
      </tr>
      <tr>
        <td>地址</td>
        <td>{{ data.organizationAddress }}</td>
        <td>电话</td>
        <td>{{ data.organizationPhone }}</td>
      </tr>
      <tr>
        <td>核定床位数</td>
        <td>{{ data.realBedNum }}</td>
        <td>机构设置证号（备案）</td>
        <td>{{ data.organizationFiling }}</td>
      </tr>
    </table>
    <br />
    <!--  员工概括 -->
    <table align="center" border="1" cellpadding="5" cellspacing="0" width="100%" class="table2">
      <caption>员工概括</caption>
      <tr>
        <td>员工总数</td>
        <td>{{ data.orgStaffTotalNum }}</td>
        <td>持证人数</td>
        <td>{{ data.orgPaperStaffNum }}</td>
        <td>管理人员</td>
        <td>{{ data.orgManagerTotalNum }}</td>
        <td>持证人数</td>
        <td>{{ data.orgPaperManagerNum }}</td>
      </tr>
    </table>
    <br />
    <!-- 申请内容 -->
    <table align="center" border="1" cellpadding="5" cellspacing="0" width="100%" class="table3">
      <caption>申请内容</caption>
      <!-- <tr>
        <td>月份</td>
        <td>人员类别</td>
        <td>人数</td>
        <td>金额</td>
      </tr>
      <tr v-for="(item) in applyData" :key="item.id">
        <td>{{ item.applyYearMonth }}</td>
        <td>{{ item.applyTypeLabel }}</td>
        <td>{{ item.applyOldmanNum }}</td>
        <td>{{ item.applyAmount }}</td>
      </tr> -->
      <!-- <tr>
              <td>合计</td>
              <td colspan="19"></td>
            </tr> -->
      <tr  style="font-weight: 700;">
        <td  rowspan="2">人员类别</td>
        <td  colspan="8">低保老人</td>
        <td colspan="6">低保边缘户老人</td>
        <td  colspan="2">经济困难、70周岁以上计生特扶及百岁老人</td>
        <td style="font-weight: 700;" rowspan="4">总金额</td>
      </tr>
      <tr style="font-weight: 700;">
        <td colspan="2">半失能</td>
        <td colspan="2">失智</td>
        <td colspan="2">半失能且失智</td>
        <td colspan="2">失能</td>
        <td colspan="2">失智、半失能</td>
        <td colspan="2">半失能且失智</td>
        <td colspan="2">失能</td>
        <td colspan="2">半失能/失能</td>
      </tr>
      <tr style="font-weight: 700;">
        <td>标准</td>
        <td colspan="2">400元/月</td>
        <td colspan="2">800元/月</td>
        <td colspan="2">1200元/月</td>
        <td colspan="2">1500元/月</td>
        <td colspan="2">400元/月</td>
        <td colspan="2">800元/月</td>
        <td colspan="2">1100元/月</td>
        <td colspan="2">400元/月以及700元/月</td>
      </tr>
      <tr style="font-weight: 700;">
        <td>月份</td>
        <td>人数</td>
        <td>金额</td>
        <td>人数</td>
        <td>金额</td>
        <td>人数</td>
        <td>金额</td>
        <td>人数</td>
        <td>金额</td>
        <td>人数</td>
        <td>金额</td>
        <td>人数</td>
        <td>金额</td>
        <td>人数</td>
        <td>金额</td>
        <td>人数</td>
        <td>金额</td>
      </tr>
      <tr v-for="(item,index) in applyData" :key="index">
        <td>{{ item }}</td>
        <template v-for="i in 8">
          <td>{{ allApplyData[item][i]?allApplyData[item][i].peopleTotal:0}}</td>
          <td>{{ allApplyData[item][i]?allApplyData[item][i].amountTotal.toFixed(2):'0.00' }}</td>
        </template>
        <td>{{ rowAmountSum(item).toFixed(2) }}</td>
      </tr>
      <tr>
        <td style="font-weight: 700;">合计</td>
        <td>{{ columnSum('1','peopleTotal') }}</td>
        <td>{{ columnSum('1','amountTotal').toFixed(2) }}</td>
        <td>{{ columnSum('2','peopleTotal') }}</td>
        <td>{{ columnSum('2','amountTotal').toFixed(2) }}</td>
        <td>{{ columnSum('3','peopleTotal') }}</td>
        <td>{{ columnSum('3','amountTotal').toFixed(2) }}</td>
        <td>{{ columnSum('4','peopleTotal') }}</td>
        <td>{{ columnSum('4','amountTotal').toFixed(2) }}</td>
        <td>{{ columnSum('5','peopleTotal') }}</td>
        <td>{{ columnSum('5','amountTotal').toFixed(2) }}</td>
        <td>{{ columnSum('6','peopleTotal') }}</td>
        <td>{{ columnSum('6','amountTotal').toFixed(2) }}</td>
        <td>{{ columnSum('7','peopleTotal') }}</td>
        <td>{{ columnSum('7','amountTotal').toFixed(2) }}</td>
        <td>{{ columnSum('8','peopleTotal') }}</td>
        <td>{{ columnSum('8','amountTotal').toFixed(2) }}</td>
        <td>{{ applyTotalSum().toFixed(2) }}</td>
      </tr>
      <tr>
        <td style="font-weight: 700;">补贴总金额:</td>
        <td colspan="9">{{ data.subsidyTotalAmount }}</td>
        <td style="font-weight: 700;">大写:</td>
        <td colspan="9">{{ data.subsidyTotalAmountText }}</td>
      </tr>
      <tr>
        <th colspan="20">本机构承诺以上及所附数据资料真实有效，如有不实，愿承担相关法规之处罚。</th>
      </tr>
      <tr>
        <th colspan="20">负责人：{{data.fillingUserName}}（单位盖章）</th>
      </tr>
      <tr>
        <th colspan="20"> {{handleDate(data.fillingDate)}}</th>
      </tr>
    </table>
    <br />
    <!-- 审核意见  -->
    <table align="center" border="1" cellpadding="5" cellspacing="0" width="100%" class="table4">
      <caption>审核意见</caption>
      <tr>
        <td rowspan="2">区民政部门意见</td>
        <td rowspan="2">{{ data.approvalCivilAffairNote }}</td>
        <td>区民政局:（章）</td>
      </tr>
      <tr>
        <td> {{handleDate(data.approvalCivilAffairDate)}}</td>
      </tr>
    </table>
  </div>
</template>

<script setup lang="ts">
import apiMod from '@/apiMod/index'
type Props = {
  nowRowData?: any
}
const props = withDefaults(defineProps<Props>(), {
  nowRowData: {}
})


let data: any = reactive({})
data = props.nowRowData
let applyData: any = ref([])
console.log(applyData)
let key = ref(1)
// let dictData = [
//   {label:'低保老人（半失能 400元/月）',value:1},
//   {label:'低保老人（失智 800元/月)',value:2},
//   {label:'低保老人（半失能且失智1200元/月）',value:3},
//   {label:'低保老人（失能1500元/月）',value:4},
//   {label:'低保边缘户老人（失智、半失能400元/月）',value:5},
//   {label:'低保边缘户老人（半失能且失智800元/月）',value:6},
//   {label:'低保边缘户老人（失能1100元/月）',value:7},
//   {label:'70周岁以上计生特扶及百岁老人（半失能400元/月、700元/月',value:8},
// ]
let allApplyData:any = reactive({})
// 获取申请数据
let getApplyData = (id) => {
  // apiMod.dpOrgFiveSubsidyApply_page({ headId: id }).then(res => {
  //   applyData = res.data.records
  //   key.value = Math.random()
  // })
  
  apiMod.view_dpOrgFiveSubsidyApply_list({ headId: id,pageParaPO:{size:1000000,current:1} }).then(res=>{
    allApplyData = res.data
    console.log('卡卡打的',allApplyData['202308'])
    applyData.value =  Object.keys(res.data)
  })
}
const columnSum = (type,key) =>{
  let sum = 0
  applyData.value.forEach(el => {
    if(allApplyData[el][type]){
      sum+=allApplyData[el][type][key]
    }
  })
  return sum
}
const rowAmountSum = (key) => {
  let sum = 0
  for(let i=1;i<=8;i++){
    if(allApplyData[key][i]){
      sum+=allApplyData[key][i].amountTotal
    }
  }
  return sum
}
// 申请总金额需要加上
const applyTotalSum = () => {
  let sum = 0
  applyData.value.forEach(el=>{
    sum+=rowAmountSum(el)
  })
  return sum
}
getApplyData(props.nowRowData.soleValue)
// 处理时间，年月日
const handleDate = (date) =>{
  if(date){
    let dateList = date.split('-')
    return dateList[0]+'年'+dateList[1]+'月'+dateList[2]+'日'
  }else{
    return '年 月 日'
  }
}
</script>
<style scoped lang="scss">
.table1>tr>td:nth-child(odd) {
  font-weight: 700; 
}
.table2>tr>td:nth-child(odd) {
  font-weight: 700; 
}

.table4>tr>td:nth-child(odd) {
  font-weight: 700; 
}
</style>